"""
用户、用户类别Model
最后修改：3.29
修改人：陈泯全
"""
from sqlalchemy import Column, Integer, String,ForeignKey
from sqlalchemy.orm import relationship,backref
from utils.dataBase import Base

class User(Base):
    __tablename__ = "user"
    uid = Column(Integer,unique=True ,primary_key=True)
    username = Column(String(50), unique=True)
    passward = Column(String(255), unique=False)
    phone = Column(Integer, unique=False)
    mail = Column(String(50), unique=False)
    auth = Column(String(50), unique=False)
    userclassifiy = Column(Integer, ForeignKey('userclassifies.cid'))
    score = Column(Integer, unique=False)

    userclassifies = relationship('Userclassifies',backref=backref('users', lazy=True))

    def __init__(self, username, passward, phone, mail, auth, userclassifiy, score):
        self.username = username
        self.passward = passward
        self.phone = phone
        self.mail  = mail
        self.auth = auth
        self.userclassifiy = userclassifiy
        self.score = score

    def __repr__(self):
        return '<User %r>' % self.username


class Userclassifies(Base):
    __tablename__ = "userclassifies"
    cid = Column(Integer, primary_key=True)
    classname = Column(String(50), unique=True, nullable=False)
    def __init__(self,classname):
        self.classname = classname

    def __repr__(self):
        return '<Userclassifies %r>' % self.classname


class Expert(Base):
    __tablename__ = "expert"
    eid = Column(Integer, primary_key=True)
    ename = Column(String(50), unique=False)
    edegree = Column(String(100), unique=False)
    pic1 = Column(String, unique=True)
    pic2 = Column(String, unique=True)
    pic3 = Column(String, unique=True)
    userid = Column(Integer, ForeignKey('user.uid'))

    useridkey = relationship('User', backref=backref('experts', lazy=True))

    def __init__(self,name ,degree,pic1,pic2 ,pic3,userId):
        self.ename = name
        self.edegree = degree
        self.pic1 = pic1
        self.pic2 = pic2
        self.pic3 = pic3
        self.userid = userId

    def __repr__(self):
        return '<Expert %r>' % self.ename